
import uuid

from common import *

class IndexHandler(pyrestful.rest.RestHandler):

    @get(_path='/', _produces=mediatypes.APPLICATION_JSON)
    def show_index(self):

        try:
            #self.set_secure_cookie('username' , 'jamesduan')
            self.set_header('Access-Control-Allow-Origin', '*')
            self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
            self.set_header('Access-Control-Max-Age', 1000)
            self.set_header('Access-Control-Allow-Headers', '*')
            self.set_header('Content-type', 'application/json')
            #self.set_secure_cookie('_nick_name', 'jamesduan')
            #self.set_secure_cookie('_access_token', ''.join(str(uuid.uuid4()).split('-')))
            self.set_header('_Token', ''.join(str(uuid.uuid4()).split('-')))

            return {
                    "records":[
                                {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
                                {"Name":"Ana Trujillo Emparedados y helados","City":"D.F.","Country":"Mexico"},
                                {"Name":"Antonio Moreno Taque","City":"ico D.F.","Country":"Mexico"},
                                {"Name":"Around the Horn","City":"London","Country":"UK"},
                                {"Name":"B's Beverages","City":"London","Country":"UK"},
                                {"Name":"Berglunds snab","City":"L","Country":"Sweden"},
                                {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
                                {"Name":"Blondel ","City":"Strasbourg","Country":"France"},
                                {"Name":"B Comidas preparadas","City":"Madrid","Country":"Spain"},
                                {"Name":"Bon app'","City":"Marseille","Country":"France"},
                                {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
                                {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
                                {"Name":"Centro comercial Moctezuma","City":"co D.F.","Country":"Mexico"},
                                {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
                                {"Name":"Comcio Mineiro","City":"Paulo","Country":"Brazil"}
                            ]
                    }
        except Exception ,e:
            logger.error(e)

